package com.s.core.persist.mapper;

import com.s.core.root.D;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author zhangjiangnan
 */
@Mapper
public interface DailyMapper {
    /**
     * 全量新增单个个股的数据
     */
    @Insert("insert into daily1(code, close,vol,pos1,date," +
            "pre_close,high,pos2,pos3,pos4,pos5,pos6,pos7,pos8,pos9,pos10," +
            "pos11,pos12,pos13,pos14,pos15,pos16,pos17,pos18,pos19,pos20,pos21,pos22,pos23,pos24,pos25,pos30,pos40,pos50,pos60,pos80,pos100,pos120) " +
            "values(#{code}, #{close},#{vol},#{pos1},#{date}," +
            "#{preClose},#{high},#{pos2},#{pos3},#{pos4},#{pos5},#{pos6},#{pos7},#{pos8},#{pos9},#{pos10}," +
            "#{pos11},#{pos12},#{pos13},#{pos14},#{pos15},#{pos16},#{pos17},#{pos18},#{pos19},#{pos20}," +
            "#{pos21},#{pos22},#{pos23},#{pos24},#{pos25},#{pos30},#{pos40},#{pos50},#{pos60},#{pos80},#{pos100},#{pos120})")
    int add(@Param("code") String code, @Param("close") String close, @Param("vol") String vol,
            @Param("pos1") Integer pos1, @Param("date") String date,
            @Param("preClose") String preClose,
            @Param("high") String high,
            @Param("pos2") Integer pos2,
            @Param("pos3") Integer pos3,
            @Param("pos4") Integer pos4,
            @Param("pos5") Integer pos5,
            @Param("pos6") Integer pos6,
            @Param("pos7") Integer pos7,
            @Param("pos8") Integer pos8,
            @Param("pos9") Integer pos9,
            @Param("pos10") Integer pos10,
            @Param("pos11") Integer pos11,
            @Param("pos12") Integer pos12,
            @Param("pos13") Integer pos13,
            @Param("pos14") Integer pos14,
            @Param("pos15") Integer pos15,
            @Param("pos16") Integer pos16,
            @Param("pos17") Integer pos17,
            @Param("pos18") Integer pos18,
            @Param("pos19") Integer pos19,
            @Param("pos20") Integer pos20,
            @Param("pos21") Integer pos21,
            @Param("pos22") Integer pos22,
            @Param("pos23") Integer pos23,
            @Param("pos24") Integer pos24,
            @Param("pos25") Integer pos25,
            @Param("pos30") Integer pos30,
            @Param("pos40") Integer pos40,
            @Param("pos50") Integer pos50,
            @Param("pos60") Integer pos60,
            @Param("pos80") Integer pos80,
            @Param("pos100") Integer pos100,
            @Param("pos120") Integer pos120);

    /**
     * 获取daily全量
     */
    @Select("select code as code,date as date,close as close,vol as vol,pre_close as preClose,high as high," +
            "pos1 as pos1," +
            "pos2,pos3,pos4,pos5,pos6,pos7,pos8,pos9,pos10,pos11,pos12,pos13,pos14,pos15,pos16,pos17,pos18,pos19,pos20,pos21,pos22,pos23,pos24,pos25," +
            "pos30,pos40,pos50,pos60,pos80,pos100,pos120 " +
            "from daily1 where " +
            "date >= (select * from (SELECT DISTINCT (date) FROM daily1 where date <= #{recentDate} ORDER BY date DESC limit #{days}) as a order by date  limit 1) " +
            "and date <= #{recentDate} " +
            "order by date desc")
    List<D> allDaily(@Param("recentDate") String recentDate, @Param("days") Integer days);

    /**
     * 删除个股
     */
    @Update("delete from daily1 where code = #{code}")
    int del(@Param("code") String code);
}